package com.cxyd.modules.job.task.logicTask;

import com.cxyd.common.utils.DateUtils;
import com.cxyd.modules.wms.service.OrderService;
import com.cxyd.modules.wms.service.PostWcsService;
import com.cxyd.modules.wms.service.PurchaseService;
import com.cxyd.modules.wms.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component("data-backup")
@Slf4j
public class DataBackupTask {

    private static final Integer PAGE_NUM = 50;
    private static final Integer DAY_AGO = -5;

    private final TaskService taskService;
    private final PostWcsService postWcsService;
    private final PurchaseService purchaseService;
    private final OrderService orderService;

    public DataBackupTask(TaskService taskService, PostWcsService postWcsService, PurchaseService purchaseService, OrderService orderService) {
        this.taskService = taskService;
        this.postWcsService = postWcsService;
        this.purchaseService = purchaseService;
        this.orderService = orderService;
    }

    public void doBackUp() {
        Date date = DateUtils.addDateDays(new Date(), DAY_AGO);
        taskService.backUp(date, PAGE_NUM);
        postWcsService.backUp(date, PAGE_NUM);
        purchaseService.backUp(date, PAGE_NUM);
        orderService.backUp(date, PAGE_NUM);
    }

}
